/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.schnipsel.swt.dialog.konfig;

import org.eclipse.swt.widgets.Composite;

import de.mnit.basis.daten.konstant.position.POSITION;
import de.mnit.basis.daten.struktur.liste.Liste;
import de.mnit.basis.daten.struktur.liste.S_Liste;
import de.mnit.basis.swt.anw.A_MN_Gruppe;
import de.mnit.basis.swt.dialog.SWT_Dialog;
import de.mnit.basis.swt.element.S_SWT_Komponente;
import de.mnit.basis.swt.element.steuer.SWT_Label;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.SWT_Auswahl;
import de.mnit.basis.swt.layout.LayoutGitter;
import de.mnit.basis.sys.sprache.S;
import de.mnit.schnipsel.div.KonfigLokal;
import de.mnit.schnipsel.zentral.SC_SPRACHE;

/**
 * @author Michael Nitsche
 * 04.10.2010	Erstellt
 */
public class K_KonfigAllgemein extends A_MN_Gruppe<K_KonfigAllgemein> implements S_KonfigSeite<K_KonfigAllgemein> {

	public static void main(String[] args)   { start(K_KonfigAllgemein.class,450,400); }


	private static final S s=new S(K_KonfigAllgemein.class);
	public final SWT_Label		kTxtSprache	= new SWT_Label();
	public final SWT_Auswahl	kSprache	= new SWT_Auswahl().s1_NurLesbar();
	private SC_SPRACHE start=null;


	public boolean oeffnen() {
		int sprachNr=KonfigLokal.i().anwSprache();
		SC_SPRACHE sprache=SC_SPRACHE.gib(sprachNr);
		this.start=sprache;

		this.kSprache.sText(sprache.name);
		return true;
	}

	public boolean speichern() {
		String text=this.kSprache.gText();
		for(SC_SPRACHE sp : SC_SPRACHE.values())
			if(sp.name.equals(text) && sp!=start) {
				KonfigLokal.i().anwSprache(sp);
				SWT_Dialog.hinweis(s.t("Diese Änderung wird erst beim nächsten Start aktiv!"));
			}
		return true;
	}

	protected S_SWT_Komponente<?, ? extends Composite> layout() {
		return LayoutGitter.neu()
			.sAussenabstand(5)
			.sSpaltenAnzahl(2)
			.sKomponente(t.kTxtSprache)
				.sBreite(100)
				.sPosition(POSITION.LINKS)
				.fertig()
			.sKomponente(t.kSprache)
//				.sFlexibelH()
				.fertig()
		;
	}

	protected void initStyle() {
		this.kTxtSprache.sText(s.t("Sprache:"));
		S_Liste<String> sprachen=Liste.neu();
		for(SC_SPRACHE sp : SC_SPRACHE.values())
			sprachen.plus(sp.name);
		this.kSprache.plus(sprachen.zuArray(String.class));
	}

	protected void initEvents() {
	}

}
